package jHaggis;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
/**
 * @author Thomas Felder
 *
 */
public class jTransScrollPaneWooden extends JScrollPane {

	public Image background_Image;
	/**
	 * Generiert eine transparente JScrollPane mit spezifiziertem Hintergrundbild.
	 * 
	 * @param JCompononent c
	 * @param String path
	 * @author Thomas Felder
	 *
	 */
	public jTransScrollPaneWooden(JComponent c, String path) {
		super(c, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		this.setImage(path);
		
		this.setBorder(null);
		this.setOpaque(false);
		this.getViewport().setOpaque(false);
		this.setBorder(BorderFactory.createEmptyBorder(8, 8, 10, 8)); //top left bottom right
		this.getVerticalScrollBar().setUnitIncrement(16);
		resizeBackground(background_Image, getPreferredSize().width,
				getPreferredSize().height);
	}
	public void setImage(String path) {
		this.background_Image = (new ImageIcon(this.getClass().getClassLoader().getResource(path))).getImage();
	}
	private void resizeBackground(Image img, int width, int height) {

		Image newImg = img.getScaledInstance(width, height,
				java.awt.Image.SCALE_SMOOTH);
		this.background_Image = newImg;
	}

	@Override
	protected void paintComponent(Graphics g) {
		Graphics2D g2d = (Graphics2D) g.create();
		g2d.drawImage(background_Image, 0, 0, this);
		super.paintComponent(g2d);
		g2d.dispose();
	}


}
